Malaysia Covid19 Cases Updates

Prepared By: Zahiruddin Zahidanishah

In [1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import plotly.graph_objects as go
import plotly.express as px
from plotly.subplots import make_subplots
import dataframe_image as dfi
import adjustText as aT
from jupyterthemes import jtplot
#import requests
import cufflinks as cf
#from bs4 import BeautifulSoup as bs
jtplot.style(theme='monokai', context='notebook', ticks=True, grid=False) 
import warnings
warnings.filterwarnings('ignore')
%matplotlib inline

from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot 
init_notebook_mode(connected=True)
cf.go_offline()

from IPython.display import display_html
def display_side_by_side(*args):
    html_str=''
    for df in args:
        html_str+=df.to_html()
    display_html(html_str.replace('table','table style="display:inline"'),raw=True)
In [2]:
#Covid19 Malaysia States Dataset from MOH, Malaysia Github accounts 
df_states_cases = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/cases_state.csv')
df_states_deaths = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/deaths_state.csv')
df_states_hosp = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/hospital.csv')
df_states_icu = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/icu.csv')
df_states_pkrc = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/pkrc.csv')
df_states_test = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/tests_state.csv')
df_states_vaksin = pd.read_csv('https://raw.githubusercontent.com/CITF-Malaysia/citf-public/main/vaccination/vax_state.csv')
df_states_pop = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/static/population.csv')
In [3]:
df_hosp_daily = df_states_hosp.groupby('date').sum().reset_index()
df_hosp_daily['admitted_covid_cum'] = df_hosp_daily['admitted_covid'].cumsum()
df_hosp_daily['discharged_covid_cum'] = df_hosp_daily['discharged_covid'].cumsum()
df_icu_daily = df_states_icu.groupby('date').sum().reset_index()
df_icu_daily['icu_covid_cum'] = df_icu_daily['icu_covid'].cumsum()
df_pkrc_daily = df_states_pkrc.groupby('date').sum().reset_index()
df_pkrc_daily['admitted_covid_cum'] = df_pkrc_daily['admitted_covid'].cumsum()
df_pkrc_daily['discharged_covid_cum'] = df_pkrc_daily['discharged_covid'].cumsum()
In [4]:
#Selecting the required columns
df_states_cases = df_states_cases[['date','state','cases_new','cases_recovered','cases_pvax','cases_fvax']]
df_date_start = df_states_cases.head(1)
df_date_end = df_states_cases.tail(1)
df_states_deaths = df_states_deaths[['date','state','deaths_new_dod','deaths_bid_dod','deaths_pvax','deaths_fvax']]
df_states_hosp = df_states_hosp[['date','state','admitted_covid','discharged_covid']]
df_states_vaksin = df_states_vaksin[['date','state','daily_partial','daily_full','daily_booster','daily']]
df_states_pop = df_states_pop[['state','pop']]
In [5]:
#Grouping and summation the detasets based on states columns
df_cases = df_states_cases.groupby('state').sum()
df_deaths = df_states_deaths.groupby('state').sum()
df_hosp = df_states_hosp.groupby('state').sum()
df_vaksin = df_states_vaksin.groupby('state').sum()
In [6]:
#Dataset for overall Malaysia Covid19
df_mas_cases = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/cases_malaysia.csv')
df_mas_deaths = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/deaths_malaysia.csv')
df_mas_test = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/tests_malaysia.csv')
df_mas_vaksin = pd.read_csv('https://raw.githubusercontent.com/CITF-Malaysia/citf-public/main/vaccination/vax_malaysia.csv')
df_mas_pop = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/static/population.csv')
df_mas_aefi = pd.read_csv('https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/vaccination/aefi.csv')
In [7]:
df_mas_vaksin['Total Pfizer'] = df_mas_vaksin['pfizer1'] + df_mas_vaksin['pfizer2']
df_mas_vaksin['Total Sinovac'] = df_mas_vaksin['sinovac1'] + df_mas_vaksin['sinovac2']
df_mas_vaksin['Total AstraZ'] = df_mas_vaksin['astra1'] + df_mas_vaksin['astra2']
df_mas_vaksin['Cum. Daily'] = df_mas_vaksin['daily_full'].cumsum()
df_mas_vaksin['Population'] = df_states_pop.at[df_states_pop.index[0],'pop']
df_mas_vaksin['Vax. (%)'] = (df_mas_vaksin['Cum. Daily']/df_mas_vaksin['Population'])*100
In [8]:
df_mas_cases = df_mas_cases[['date','cases_new','cases_recovered','cases_pvax','cases_fvax','cases_active']]
df_mas_deaths = df_mas_deaths[['date','deaths_new_dod','deaths_bid_dod','deaths_pvax','deaths_fvax']]
df_mas_vaksin = df_mas_vaksin[['date', 'daily_partial', 'daily_full', 'daily_booster', 'daily', 'Total Pfizer',
                               'Total Sinovac', 'Total AstraZ', 'cansino', 'Cum. Daily', 'Vax. (%)']]
In [9]:
df_mas = pd.merge(df_mas_cases, df_mas_deaths, on='date')
In [10]:
df_mas = pd.merge(df_mas, df_mas_vaksin, on='date')
In [11]:
#Merging the datasets into one datasets
df_states = pd.merge(df_cases,df_deaths,on='state')
In [12]:
df_states = pd.merge(df_states,df_hosp,on='state')
In [13]:
df_states = pd.merge(df_states,df_vaksin,on='state')
In [14]:
df_states = pd.merge(df_states,df_states_pop,on='state')
In [15]:
#Creating main tables for presentation
df_states_table = df_states
df_states_table['deaths_vax_total'] = df_states_table['deaths_pvax'] + df_states_table['deaths_fvax']
df_states_table['cases_vax_total'] = df_states_table['cases_pvax'] + df_states_table['cases_fvax']

df_states_table = df_states_table[['state','cases_new','cases_recovered','cases_vax_total','deaths_new_dod',
                                  'deaths_bid_dod','deaths_vax_total','daily_partial','daily_full','daily',
                                   'daily_booster','pop']]

df_states_table.loc['Total'] = df_states_table.sum(numeric_only=True, axis=0)
df_states_table['state'] = df_states_table['state'].replace(np.nan, 'Malaysia')

df_states_table['Cases (%)'] = df_states_table['cases_new']/df_states_table['pop']*100
df_states_table['Cases Recovered (%)'] = df_states_table['cases_recovered']/df_states_table['cases_new']*100
df_states_table['Cases Vax. (%)'] = df_states_table['cases_vax_total']/df_states_table['cases_new']*100
df_states_table['Deaths (%)'] = df_states_table['deaths_new_dod']/df_states_table['cases_new']*100
df_states_table['Deaths Vax. (%)'] = df_states_table['deaths_vax_total']/df_states_table['deaths_new_dod']*100
df_states_table['Deaths BID (%)'] = df_states_table['deaths_bid_dod']/df_states_table['deaths_new_dod']*100
df_states_table['Vax. 3D (%)'] = df_states_table['daily_booster']/df_states_table['pop']*100
df_states_table['Vax. 2D (%)'] = df_states_table['daily_full']/df_states_table['pop']*100
df_states_table['Vax. 1D (%)'] = df_states_table['daily_partial']/df_states_table['pop']*100

df_states_table.rename(columns={'state':'States','cases_new':'Cases Positive','cases_recovered':'Cases Recovered',
                               'cases_vax_total':'Cases Vax.','deaths_new_dod':'Death Cases',
                               'deaths_bid_dod':'Death BID','deaths_vax_total':'Deaths Vax.',
                               },inplace=True)#'daily':'Total Vaccinated','pop':'Population'
In [16]:
print('Report Start Date :', df_date_start.at[df_date_start.index[0],'date'])
print('Report End Date   :', df_date_end.at[df_date_end.index[0],'date'])
Report Start Date : 2020-01-25
Report End Date   : 2022-03-30
In [17]:
df_mas_cases['total_vax'] = df_mas_cases['cases_pvax'] + df_mas_cases['cases_fvax']
df_mas_cases['cum_new'] = df_mas_cases['cases_new'].cumsum()
df_mas_cases['cum_recovered'] = df_mas_cases['cases_recovered'].cumsum()
df_mas_cases['cum_vax'] = df_mas_cases['total_vax'].cumsum()
df_mas_cases['active_cum'] = df_mas_cases['cases_active'].cumsum()

df_mas_deaths['total_vax'] = df_mas_deaths['deaths_pvax'] + df_mas_deaths['deaths_fvax']
df_mas_deaths['cum_deaths'] = df_mas_deaths['deaths_new_dod'].cumsum()
df_mas_deaths['cum_vax'] = df_mas_deaths['total_vax'].cumsum()
In [18]:
df_mas_monthly = df_mas_cases.append(df_mas_deaths)

def getYearMonth(s):
  return s.split("-")[1]+"-"+s.split("-")[0]
df_mas_monthly['YearMonth']= df_mas_monthly['date'].apply(lambda x: getYearMonth(x))

df_mas_monthly = df_mas_monthly.groupby('YearMonth').sum()
df_mas_monthly = df_mas_monthly.reset_index()
df_mas_monthly['vax_total_cases'] = df_mas_monthly['cases_fvax']+df_mas_monthly['cases_pvax']
df_mas_monthly['vax_total_deaths'] = df_mas_monthly['deaths_fvax']+df_mas_monthly['deaths_pvax']
In [19]:
df_mas_yearly = df_mas_cases.append(df_mas_deaths)

def getYear(s):
  return s.split("-")[0]

def getMonth(s):
  return s.split("-")[1]

df_mas_yearly['Year']= df_mas_yearly['date'].apply(lambda x: getYear(x))
df_mas_yearly['Month']= df_mas_yearly['date'].apply(lambda x: getMonth(x))

df_mas_yearly = df_mas_yearly.groupby('Year').sum().reset_index()
df_mas_yearly['vax_total_cases'] = df_mas_yearly['cases_fvax']+df_mas_yearly['cases_pvax']
df_mas_yearly['vax_total_deaths'] = df_mas_yearly['deaths_fvax']+df_mas_yearly['deaths_pvax']
In [20]:
fig = make_subplots(rows=1, cols=2, shared_xaxes=True, vertical_spacing=0.08,
                   subplot_titles=('<b>Yearly Total Covid19 Cases & Recovered</b>',
                                   '<b>Monthly Total Covid19 Cases & Recovered</b>'))
#Graph 1
fig.append_trace(go.Bar(x = df_mas_yearly['Year'], y = df_mas_yearly['cases_new'],
                        name='Cases Positive',marker_color='red'),row=1, col=1)
fig.append_trace(go.Bar(x = df_mas_yearly['Year'], y = df_mas_yearly['cases_recovered'],
                        name='Cases Recovered',marker_color='blue'),row=1, col=1)
#Graph 2
fig.append_trace(go.Bar(x = df_mas_monthly['YearMonth'], y = df_mas_monthly['cases_new'],
                        name='Cases Positive',marker_color='red'),row=1, col=2)
fig.append_trace(go.Bar(x = df_mas_monthly['YearMonth'], y = df_mas_monthly['cases_recovered'],
                        name='Cases Recovered',marker_color='blue'),row=1, col=2)

#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=400,showlegend=False)
#fig.update_layout(height=400,showlegend=False,title_text='Yearly and Monthly Total New And Recovered Cases', title_x=0.5)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

#Plotting the graph
fig.show()
In [21]:
fig = make_subplots(rows=1, cols=2, shared_xaxes=True, vertical_spacing=0.08,
                   subplot_titles=('<b>Yearly Total Covid19 Death Cases</b>',
                                   '<b>Monthly Total Covid19 Death Cases</b>'))
#Graph 1
fig.append_trace(go.Bar(x = df_mas_yearly['Year'], y = df_mas_yearly['deaths_new_dod'],
                        name='Death Cases',marker_color='red'),row=1, col=1)
fig.append_trace(go.Bar(x = df_mas_yearly['Year'], y = df_mas_yearly['vax_total_deaths'],
                        name='Death Vax Cases',marker_color='blue'),row=1, col=1)

#Graph 2
fig.append_trace(go.Bar(x = df_mas_monthly['YearMonth'], y = df_mas_monthly['deaths_new_dod'],
                        name='Death Cases',marker_color='red'),row=1, col=2)
fig.append_trace(go.Bar(x = df_mas_monthly['YearMonth'], y = df_mas_monthly['vax_total_deaths'],
                        name='Death Vax Cases',marker_color='blue'),row=1, col=2)

#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=400,showlegend=False)
#fig.update_layout(height=400,showlegend=False,title_text='Yearly and Monthly Total New And Recovered Cases', title_x=0.5)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

#Plotting the graph
fig.show()
In [22]:
fig = make_subplots(shared_xaxes=True, specs=[[{'secondary_y': True}]])

#Graph 1
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cases_new'], name ='Positive Cases', 
               line = dict(color='blue', width=1)), secondary_y=True, row=1, col=1)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cases_recovered'], name = 'Recovered Cases',
               line = dict(color='red', width=1)), secondary_y=True, row=1, col=1)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['total_vax'], name = 'Vax. Cases',
               line = dict(color='green', width=1)), secondary_y=True, row=1, col=1)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cum_new'], name ='Cumulative Cases', 
               line = dict(color='blue', width=1)), secondary_y=False, row=1, col=1)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cum_recovered'], name = 'Cumulative Recovered',
               line = dict(color='red', width=1)), secondary_y=False, row=1, col=1)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cum_vax'], name = 'Cumulative Vax.',
               line = dict(color='green', width=1)), secondary_y=False, row=1, col=1)

fig.update_layout(title_text='Malaysia Covid19 New And Recovered Cases', title_x=0.5, showlegend=False,
                 height=600)
fig.update_xaxes(title_text='')
fig.update_annotations(font=dict(family="Helvetica", size=12))
fig.update_layout(font=dict(family="Helvetica", size=14))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

#fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              #x0='2021-10-11', x1='2021-10-11',  y0=0, y1=1000000)
#fig.add_annotation(text='90% Vax.', x='2021-10-11', y=1000000, arrowhead=3, align='center', 
                   #arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-90, showarrow=True, 
                   #xanchor="left", yanchor="bottom")
#fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              #x0='2020-09-26', x1='2020-09-26',  y0=0, y1=500000)
#fig.add_annotation(text='PRN Sabah', x='2020-09-26', y=500000, arrowhead=3, align='center', 
                   #arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-30, showarrow=True, 
                   #xanchor="left", yanchor="bottom")
#fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              #x0='2021-11-20', x1='2021-11-20',  y0=0, y1=500000)
#fig.add_annotation(text='PRN Melaka', x='2021-11-20', y=500000, arrowhead=3, align='center', 
                   #arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-30, showarrow=True, 
                   #xanchor="left", yanchor="bottom")
#fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              #x0='2021-12-06', x1='2021-12-06',  y0=0, y1=400000)
#fig.add_annotation(text='PRN Sarawak', x='2021-12-06', y=400000, arrowhead=3, align='center', 
                   #arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-30, showarrow=True, 
                   #xanchor="left", yanchor="bottom")
#fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              #x0='2021-01-12', x1='2021-01-12',  y0=0, y1=600000)
#fig.add_annotation(text='Darurat Mula', x='2021-01-12', y=600000, arrowhead=3, align='center', 
                   #arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-30, showarrow=True, 
                   #xanchor="left", yanchor="bottom")
#fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", 
              #x0='2021-08-01', x1='2021-08-01',  y0=0, y1=1100000)
#fig.add_annotation(text='Darurat Tamat', x='2021-08-01', y=1100000, arrowhead=3, align='center', 
                   #arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-30, showarrow=True, 
                   #xanchor="left", yanchor="bottom")
fig.show()
In [23]:
fig = make_subplots(shared_xaxes=True, specs=[[{'secondary_y': True}]])

#Graph 1
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_deaths['deaths_new_dod'], name ='Death Cases', 
               line = dict(color='blue', width=1)), secondary_y=True, row=1, col=1)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_deaths['total_vax'], name = 'Vax Death Cases',
               line = dict(color='red', width=1)), secondary_y=True, row=1, col=1)

fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_deaths['cum_deaths'], name ='Cum. Death Cases', 
               line = dict(color='blue', width=1)), secondary_y=False, row=1, col=1)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_deaths['cum_vax'], name = 'Cum. Vax Death Recovered',
               line = dict(color='red', width=1)), secondary_y=False, row=1, col=1)


fig.update_layout(title_text='Malaysia Covid19 Death Cases: New VS Vax', title_x=0.5, showlegend=False,
                 height=600)
fig.update_xaxes(title_text='')
fig.update_annotations(font=dict(family="Helvetica", size=12))
fig.update_layout(font=dict(family="Helvetica", size=14))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.show()
In [24]:
df_2020 = df_mas_cases.query("date >= '2020-01-01' \
                            and date <= '2020-12-31'")
df_2021 = df_mas_cases.query("date >= '2021-01-01' \
                            and date <= '2021-12-31'")
df_2022 = df_mas_cases.query("date >= '2022-01-01' \
                            and date <= '2022-12-31'")
In [25]:
df_2020['cum_2020'] = df_2020['cases_new'].cumsum()
df_2021['cum_2021'] = df_2021['cases_new'].cumsum()
df_2022['cum_2022'] = df_2022['cases_new'].cumsum()
In [26]:
death_2020 = df_mas_deaths.query("date >= '2020-01-01' \
                            and date <= '2020-12-31'")
death_2021 = df_mas_deaths.query("date >= '2021-01-01' \
                            and date <= '2021-12-31'")
death_2022 = df_mas_deaths.query("date >= '2022-01-01' \
                            and date <= '2022-12-31'")
In [27]:
death_2020['cum_2020'] = death_2020['deaths_new_dod'].cumsum()
death_2021['cum_2021'] = death_2021['deaths_new_dod'].cumsum()
death_2022['cum_2022'] = death_2022['deaths_new_dod'].cumsum()
In [28]:
fig = make_subplots(rows=1, cols=3, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}]],
                    
subplot_titles=('<b>Year 2020</b>',
                '<b>Year 2021</b>',
                '<b>Year 2022</b>'))

fig.add_trace(go.Scatter(x = df_2020['date'], y = df_2020['cases_new'], name = 'Daily Cases',
               line = dict(color='green', width=1)), secondary_y=False, row=1, col=1)
fig.add_trace(go.Scatter(x = df_2020['date'], y = df_2020['cum_2020'], name = 'Cumulative Cases',
               line = dict(color='green', width=1.5)), secondary_y=True, row=1, col=1)
fig.add_trace(go.Scatter(x = df_2020['date'], y = df_2020['cases_active'], name = 'Active Cases',
               line = dict(color='green', width=1.5)), secondary_y=True, row=1, col=1)

fig.add_trace(go.Scatter(x = df_2021['date'], y = df_2021['cases_new'], name = 'Cases Daily',
               line = dict(color='blue', width=1)), secondary_y=False, row=1, col=2)
fig.add_trace(go.Scatter(x = df_2021['date'], y = df_2021['cum_2021'], name = 'Cases',
               line = dict(color='blue', width=1.5)), secondary_y=True, row=1, col=2)
fig.add_trace(go.Scatter(x = df_2021['date'], y = df_2021['cases_active'], name = 'Active Cases',
               line = dict(color='blue', width=1.5)), secondary_y=True, row=1, col=2)

fig.add_trace(go.Scatter(x = df_2022['date'], y = df_2022['cases_new'], name = 'Daily Cases',
               line = dict(color='red', width=1)), secondary_y=False, row=1, col=3)
fig.add_trace(go.Scatter(x = df_2022['date'], y = df_2022['cum_2022'], name = 'Cumulative Cases',
               line = dict(color='red', width=1.5)), secondary_y=True, row=1, col=3)
fig.add_trace(go.Scatter(x = df_2022['date'], y = df_2022['cases_active'], name = 'Active Cases',
               line = dict(color='red', width=1.5)), secondary_y=True, row=1, col=3)

fig.update_layout(title_text='Malaysia Covid19 Cases By Year', title_x=0.5, showlegend=False,
                 height=350)
fig.update_xaxes(title_text='')
#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=350,showlegend=False)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

#Plotting the graph
fig.show()
In [29]:
fig = make_subplots(rows=1, cols=3, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}]],
                    
subplot_titles=('<b>Year 2020</b>',
                '<b>Year 2021</b>',
                '<b>Year 2022</b>'))

fig.add_trace(go.Scatter(x = death_2020['date'], y = death_2020['deaths_new_dod'], name = 'Daily Death Cases',
               line = dict(color='red', width=1)), secondary_y=False, row=1, col=1)
fig.add_trace(go.Scatter(x = death_2020['date'], y = death_2020['cum_2020'], name = 'Cumulative Death Cases',
               line = dict(color='blue', width=1.5)), secondary_y=True, row=1, col=1)

fig.add_trace(go.Scatter(x = death_2021['date'], y = death_2021['deaths_new_dod'], name = 'Daily Death Cases',
               line = dict(color='red', width=1)), secondary_y=False, row=1, col=2)
fig.add_trace(go.Scatter(x = death_2021['date'], y = death_2021['cum_2021'], name = 'Cumulative Death Cases',
               line = dict(color='blue', width=1.5)), secondary_y=True, row=1, col=2)

fig.add_trace(go.Scatter(x = death_2022['date'], y = death_2022['deaths_new_dod'], name = 'Daily Death Cases',
               line = dict(color='red', width=1)), secondary_y=False, row=1, col=3)
fig.add_trace(go.Scatter(x = death_2022['date'], y = death_2022['cum_2022'], name = 'Cumulative Death Cases',
               line = dict(color='blue', width=1.5)), secondary_y=True, row=1, col=3)


fig.update_layout(title_text='Malaysia Covid19 Death Cases By Year', title_x=0.5, showlegend=False,
                 height=350)
fig.update_xaxes(title_text='')
#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=350,showlegend=False)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

#Plotting the graph
fig.show()
In [30]:
#Creating the main key points from the datasets
print('Key Points Highlights:-')
print('-----------------------------------------------------------------')
print('1. Total Positive Cases                  :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'Cases Positive']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Cases (%)']),'%')
print('2. Total Positive Cases After Vaccinated :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'Cases Vax.']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Cases Vax. (%)']),'%')
print('3. Total Recovered Cases                 :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'Cases Recovered']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Cases Recovered (%)']),'%')
print('4. Total Death Cases                     :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'Death Cases']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Deaths (%)']),'%')
print('5. Total Death Cases After Vaccinated    :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'Deaths Vax.']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Deaths Vax. (%)']),'%')
print('6. Total 1 Dose Vaccinated               :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'daily_partial']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Vax. 1D (%)']),'%')
print('7. Total 2 Dose Vaccinated               :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'daily_full']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Vax. 2D (%)']),'%')
print('8. Total 3 Dose Vaccinated               :','{0:,.0f}'.format(df_states_table.at[df_states_table.index[16],'daily_booster']),'/','{0:.1f}'.format(df_states_table.at[df_states_table.index[16],'Vax. 3D (%)']),'%')
print('-----------------------------------------------------------------')
Key Points Highlights:-
-----------------------------------------------------------------
1. Total Positive Cases                  : 4,183,359 / 12.8 %
2. Total Positive Cases After Vaccinated : 1,613,264 / 38.6 %
3. Total Recovered Cases                 : 3,941,829 / 94.2 %
4. Total Death Cases                     : 34,938 / 0.8 %
5. Total Death Cases After Vaccinated    : 12,494 / 35.8 %
6. Total 1 Dose Vaccinated               : 27,282,491 / 83.5 %
7. Total 2 Dose Vaccinated               : 25,801,561 / 79.0 %
8. Total 3 Dose Vaccinated               : 15,711,005 / 48.1 %
-----------------------------------------------------------------
In [31]:
df_states_table.drop(['daily_partial','daily_full','pop','daily','daily_booster'],axis='columns',inplace=True)
In [32]:
df_states_table.drop(['Cases Vax.','Death BID','Deaths Vax.'],axis='columns',inplace=True)

df_states_table.style.set_caption("Malaysia Details Of Covid19 Cases At Each States").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '26px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Cases Positive':'{:,.0f}','Cases Recovered':'{:,.0f}','Cases Vax.':'{:,.0f}','Death Cases':'{:,.0f}',
     'Deaths (%)':'{:,.1f}','Deaths BID':'{:,.0f}','Deaths Vax.':'{:,.0f}','Cases (%)':'{:,.1f}',
     'Cases Recovered (%)':'{:,.1f}','Cases Vax. (%)':'{:,.1f}','Vax. 2D (%)':'{:,.1f}','Vax. 1D (%)':'{:,.1f}',
     'Deaths Vax. (%)':'{:,.1f}','Deaths BID (%)':'{:,.1f}','Vax. 3D (%)':'{:,.1f}'}
).set_properties(subset=['States'],**{'text-align': 'left'}).apply(
    lambda x: ['background: salmon' if x.name in ['Total'] else '' for i in x], axis=1).hide_index()
Out[32]:
Malaysia Details Of Covid19 Cases At Each States
States Cases Positive Cases Recovered Death Cases Cases (%) Cases Recovered (%) Cases Vax. (%) Deaths (%) Deaths Vax. (%) Deaths BID (%) Vax. 3D (%) Vax. 2D (%) Vax. 1D (%)
Johor 371,515 357,447 4,422 9.8 96.2 37.0 1.2 39.3 13.6 54.7 80.8 86.3
Kedah 291,307 278,786 2,561 13.3 95.7 40.7 0.9 35.8 17.3 32.9 72.1 75.3
Kelantan 244,688 239,594 1,409 12.7 97.9 46.4 0.6 35.9 27.7 16.4 61.4 63.4
Melaka 116,183 109,638 1,086 12.4 94.4 36.0 0.9 37.7 14.1 56.8 76.8 82.3
Negeri Sembilan 188,551 177,580 1,449 16.7 94.2 31.1 0.8 30.2 12.6 57.2 84.5 89.4
Pahang 165,318 157,322 941 9.8 95.2 42.0 0.6 36.8 13.4 35.9 70.1 73.6
Perak 188,705 177,391 1,821 7.5 94.0 38.8 1.0 44.7 15.0 45.0 74.4 78.4
Perlis 16,673 15,697 174 6.5 94.1 57.6 1.0 46.0 4.6 30.1 80.3 83.8
Pulau Pinang 266,934 258,577 1,941 15.0 96.9 41.2 0.7 40.3 21.4 59.2 86.3 90.8
Sabah 367,195 349,402 3,110 9.6 95.2 41.1 0.8 25.6 40.7 22.9 62.8 63.4
Sarawak 297,702 286,056 1,685 10.5 96.1 48.9 0.6 48.4 21.6 54.9 75.9 84.8
Selangor 1,182,383 1,077,234 10,519 18.0 91.1 34.9 0.9 33.2 21.6 60.4 73.4 78.1
Terengganu 120,925 116,182 843 9.5 96.1 45.2 0.7 43.5 12.6 26.8 69.3 71.6
W.P. Kuala Lumpur 326,514 303,704 2,791 18.7 93.0 31.9 0.9 34.7 26.0 97.5 174.0 184.0
W.P. Labuan 20,816 20,268 154 20.8 97.4 24.3 0.7 9.7 28.6 48.0 80.0 87.8
W.P. Putrajaya 17,950 16,951 32 15.5 94.4 40.5 0.2 40.6 3.1 69.4 127.3 137.7
Malaysia 4,183,359 3,941,829 34,938 12.8 94.2 38.6 0.8 35.8 21.1 48.1 79.0 83.5
In [33]:
df_states_graph = df_states
df_states_graph['vaksin_percentage_partial'] = df_states_graph['daily_partial']/df_states_graph['pop']*100
df_states_graph['vaksin_percentage_full'] = df_states_graph['daily_full']/df_states_graph['pop']*100
df_states_graph['deaths_vax_total'] = df_states_graph['deaths_pvax'] + df_states_graph['deaths_fvax']
df_states_graph['cases_vax_total'] = df_states_graph['cases_pvax'] + df_states_graph['cases_fvax']
In [34]:
df_mas_deaths['deaths_vax_total'] = df_mas_deaths['deaths_pvax'] + df_mas_deaths['deaths_fvax']
df_mas['deaths_vax_total'] = df_mas['deaths_pvax'] + df_mas['deaths_fvax']
df_mas_test['total_test'] = df_mas_test['rtk-ag'] + df_mas_test['pcr']
df_mas_test['cum_total'] = df_mas_test['total_test'].cumsum()
In [35]:
df_mas_new = df_mas[['date','cases_new','deaths_new_dod']]
df_mas_new['cases_new_7'] = df_mas_new['cases_new'].shift(7)
df_mas_new['cases_new_14'] = df_mas_new['cases_new'].shift(14)
df_mas_new['cases_new_21'] = df_mas_new['cases_new'].shift(21)
df_mas_new['deaths_new_7'] = df_mas_new['deaths_new_dod'].shift(7)
df_mas_new['deaths_new_14'] = df_mas_new['deaths_new_dod'].shift(14)
df_mas_new['deaths_new_21'] = df_mas_new['deaths_new_dod'].shift(21)
df_mas_new = df_mas_new.tail(7)
df_mas_new['cum_new'] = df_mas_new['cases_new'].cumsum()
df_mas_new['cum_new_7'] = df_mas_new['cases_new_7'].cumsum()
df_mas_new['cum_new_14'] = df_mas_new['cases_new_14'].cumsum()
df_mas_new['cum_new_21'] = df_mas_new['cases_new_21'].cumsum()
df_mas_new['cum_deaths_new'] = df_mas_new['deaths_new_dod'].cumsum()
df_mas_new['cum_deaths_7'] = df_mas_new['deaths_new_7'].cumsum()
df_mas_new['cum_deaths_14'] = df_mas_new['deaths_new_14'].cumsum()
df_mas_new['cum_deaths_21'] = df_mas_new['deaths_new_21'].cumsum()
In [36]:
print('Four Weeks Cumulative Daily Cases Comparison Analysis:-')
print('--------------------------------------------')
print('Average Week 1: ', '{0:,.0f}'.format(df_mas_new['cum_new'].mean()), '(', '{0:,.0f}'.format(df_mas_new['cum_new'].mean()-df_mas_new['cum_new_7'].mean()),'diff.)')
print('Average Week 2: ', '{0:,.0f}'.format(df_mas_new['cum_new_7'].mean()), '(', '{0:,.0f}'.format(df_mas_new['cum_new_7'].mean()-df_mas_new['cum_new_14'].mean()),'diff.)')
print('Average Week 3: ', '{0:,.0f}'.format(df_mas_new['cum_new_14'].mean()), '(', '{0:,.0f}'.format(df_mas_new['cum_new_14'].mean()-df_mas_new['cum_new_21'].mean()),'diff.)')
print('Average Week 4: ', '{0:,.0f}'.format(df_mas_new['cum_new_21'].mean()), '-')
print('--------------------------------------------')
print('Four Weeks Daily Cases Comparison Analysis:-')
print('--------------------------------------------')
print('Average Week 1:', '{0:,.0f}'.format(df_mas_new['cases_new'].mean()), '(', '{0:,.0f}'.format(df_mas_new['cases_new'].mean()-df_mas_new['cases_new_7'].mean()),'diff.)')
print('Average Week 2:', '{0:,.0f}'.format(df_mas_new['cases_new_7'].mean()), '(', '{0:,.0f}'.format(df_mas_new['cases_new_7'].mean()-df_mas_new['cases_new_14'].mean()),'diff.)')
print('Average Week 3:', '{0:,.0f}'.format(df_mas_new['cases_new_14'].mean()), '(', '{0:,.0f}'.format(df_mas_new['cases_new_14'].mean()-df_mas_new['cases_new_21'].mean()),'diff.)')
print('Average Week 4:', '{0:,.0f}'.format(df_mas_new['cases_new_21'].mean()), '-')
print('--------------------------------------------')
Four Weeks Cumulative Daily Cases Comparison Analysis:-
--------------------------------------------
Average Week 1:  84,099 ( -13,777 diff.)
Average Week 2:  97,876 ( -16,930 diff.)
Average Week 3:  114,806 ( -7,262 diff.)
Average Week 4:  122,068 -
--------------------------------------------
Four Weeks Daily Cases Comparison Analysis:-
--------------------------------------------
Average Week 1: 19,283 ( -3,617 diff.)
Average Week 2: 22,900 ( -4,412 diff.)
Average Week 3: 27,312 ( -3,026 diff.)
Average Week 4: 30,338 -
--------------------------------------------
In [37]:
fig = make_subplots(rows=1, cols=4, shared_xaxes=True, vertical_spacing=0.08,
                   subplot_titles=('<b>New Confirmed Cases Daily</b>',
                                   '<b>New Confirmed Cases Cumulative</b>',
                                   '<b>New Deaths Cases Daily</b>',
                                   '<b>New Deaths Cases Cumulative</b>'))
#Graph 1
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cases_new'],name='Week 1', mode="lines",
                           line = dict(color='red',width=0.5)),row=1, col=1)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cases_new_7'],name='Week 2', mode="lines",
                           line = dict(color='blue',width=0.5)),row=1, col=1)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cases_new_14'],name='Week 3', mode="lines",
                           line = dict(color='green',width=0.5)),row=1, col=1)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cases_new_21'],name='Week 4', mode="lines",
                           line = dict(color='purple',width=0.5)),row=1, col=1)
fig.add_hline(y=df_mas_new['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Week 1", annotation_position="bottom left",row=1, col=1)
fig.add_hline(y=df_mas_new['cases_new_7'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Week 2", annotation_position="bottom right",row=1, col=1)
fig.add_hline(y=df_mas_new['cases_new_14'].mean(), line_dash="dot",line_color="green",
              annotation_text="Ave. Week 3", annotation_position="bottom left",row=1, col=1)
fig.add_hline(y=df_mas_new['cases_new_21'].mean(), line_dash="dot",line_color="purple",
              annotation_text="Ave. Week 4", annotation_position="bottom right",row=1, col=1)
#Graph 2
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_new'],name='Week 1', mode="lines",
                           line = dict(color='red',width=0.5)),row=1, col=2)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_new_7'],name='Week 2', mode="lines",
                           line = dict(color='blue',width=0.5)),row=1, col=2)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_new_14'],name='Week 3', mode="lines",
                           line = dict(color='green',width=0.5)),row=1, col=2)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_new_21'],name='Week 4', mode="lines",
                           line = dict(color='purple',width=0.5)),row=1, col=2)
fig.add_hline(y=df_mas_new['cum_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Week 1", annotation_position="bottom left",row=1, col=2)
fig.add_hline(y=df_mas_new['cum_new_7'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Week 2", annotation_position="bottom right",row=1, col=2)
fig.add_hline(y=df_mas_new['cum_new_14'].mean(), line_dash="dot",line_color="green",
              annotation_text="Ave. Week 3", annotation_position="top left",row=1, col=2)
fig.add_hline(y=df_mas_new['cum_new_21'].mean(), line_dash="dot",line_color="purple",
              annotation_text="Ave. Week 4", annotation_position="bottom right",row=1, col=2)
#Graph 3
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['deaths_new_dod'],name='Week 1', mode="lines",
                           line = dict(color='red', width=0.5)),row=1, col=3)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['deaths_new_7'],name='Week 2', mode="lines",
                           line = dict(color='blue', width=0.5)),row=1, col=3)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['deaths_new_14'],name='Week 3', mode="lines",
                           line = dict(color='green', width=0.5)),row=1, col=3)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['deaths_new_21'],name='Week 4', mode="lines",
                           line = dict(color='purple', width=0.5)),row=1, col=3)
fig.add_hline(y=df_mas_new['deaths_new_dod'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Week 1", annotation_position="bottom left",row=1, col=3)
fig.add_hline(y=df_mas_new['deaths_new_7'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Week 2", annotation_position="bottom right",row=1, col=3)
fig.add_hline(y=df_mas_new['deaths_new_14'].mean(), line_dash="dot",line_color="green",
              annotation_text="Ave. Week 3", annotation_position="bottom left",row=1, col=3)
fig.add_hline(y=df_mas_new['deaths_new_21'].mean(), line_dash="dot",line_color="purple",
              annotation_text="Ave. Week 4", annotation_position="bottom right",row=1, col=3)
#Graph 4
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_deaths_new'],name='Week 1', mode="lines",
                           line = dict(color='red', width=0.5)),row=1, col=4)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_deaths_7'],name='Week 2', mode="lines",
                           line = dict(color='blue', width=0.5)),row=1, col=4)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_deaths_14'],name='Week 3', mode="lines",
                           line = dict(color='green', width=0.5)),row=1, col=4)
fig.append_trace(go.Scatter(x = df_mas_new['date'], y = df_mas_new['cum_deaths_21'],name='Week 4', mode="lines",
                           line = dict(color='purple', width=0.5)),row=1, col=4)
fig.add_hline(y=df_mas_new['cum_deaths_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Week 1", annotation_position="bottom left",row=1, col=4)
fig.add_hline(y=df_mas_new['cum_deaths_7'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Week 2", annotation_position="bottom right",row=1, col=4)
fig.add_hline(y=df_mas_new['cum_deaths_14'].mean(), line_dash="dot",line_color="green",
              annotation_text="Ave. Week 3", annotation_position="bottom left",row=1, col=4)
fig.add_hline(y=df_mas_new['cum_deaths_21'].mean(), line_dash="dot",line_color="purple",
              annotation_text="Ave. Week 4", annotation_position="top right",row=1, col=4)
#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=400,showlegend=False,title_text="Malaysia Covid19 Latest Cases In Details (4 Week Comparison)", title_x=0.5)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black',
                visible=True, showticklabels=False)
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [38]:
df_mas_cases['cum_new'] = df_mas_cases['cases_new'].cumsum()
df_mas_cases['cum_recovered'] = df_mas_cases['cases_recovered'].cumsum()
df_mas_deaths['cum_deaths'] = df_mas_deaths['deaths_new_dod'].cumsum()
df_mas_deaths['cum_deaths_vax'] = df_mas_deaths['deaths_vax_total'].cumsum()
In [39]:
fig = make_subplots(rows=2, cols=4, shared_xaxes=True, vertical_spacing=0.08,
                    specs=[[{'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}], 
                           [{'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}]],

subplot_titles=('<b>Cases: Total VS Recover</b>',
                '<b>ICU Daily Admitted</b>',
                '<b>Hosp.: Admit VS Discharge</b>',
                '<b>PKRC: Admitted VS Discharged</b>',
                '<b>Deaths: Total, BID & Vax.</b>',
                '<b>Total Daily Covid19 Test</b>',
                '<b>States Hosp. Admission & Discharge</b>',
                '<b>States Vax. (%): 1D VS 2D</b>'))

#Graph 1
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cases_new'], name='Positive Cases',
                           line = dict(color='red',width=0.5)), row=1, col=1, secondary_y=True)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cum_new'], name='Positive Cases',
                           line = dict(color='red',width=1)), row=1, col=1, secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cases_recovered'],name='Recovered Cases',
                            line = dict(color='blue',width=0.5)),row=1, col=1, secondary_y=True)
fig.add_trace(go.Scatter(x = df_mas_cases['date'], y = df_mas_cases['cum_recovered'],name='Recovered Cases',
                            line = dict(color='blue',width=1)),row=1, col=1, secondary_y=False)
fig.add_hline(y=df_mas_cases['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Cases", annotation_position="bottom left",row=1, col=1)
fig.add_hline(y=df_mas_cases['cases_recovered'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Recovered", annotation_position="top left",row=1, col=1)
#Graph 2
fig.add_trace(go.Scatter(x = df_icu_daily['date'], y = df_icu_daily['icu_covid'],name='ICU Covid',
                           line = dict(color='blue', width=0.5)),row=1, col=2, secondary_y=True)
fig.add_trace(go.Scatter(x = df_icu_daily['date'], y = df_icu_daily['icu_covid_cum'],name='ICU Covid',
                           line = dict(color='red', width=0.5)),row=1, col=2, secondary_y=False)
fig.add_hline(y = df_icu_daily['icu_covid'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Daily", annotation_position="bottom left",row=1, col=2)
fig.add_hline(y = df_icu_daily['icu_covid_cum'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Cum.", annotation_position="bottom left",row=1, col=2)
# Graph 3
fig.add_trace(go.Scatter(x = df_mas_deaths['date'], y = df_mas_deaths['deaths_new_dod'],name='Deaths Cases',
                           line = dict(width=0.5, color='blue')),row=2, col=1, secondary_y=True)
fig.add_trace(go.Scatter(x = df_mas_deaths['date'], y = df_mas_deaths['cum_deaths'],name='Deaths Cases',
                           line = dict(width=1, color='blue')),row=2, col=1, secondary_y=False)
fig.add_hline(y=df_mas_deaths['deaths_new_dod'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Daily Deaths", annotation_position="top left",row=2, col=1)
fig.add_trace(go.Scatter(x = df_mas_deaths['date'], y = df_mas_deaths['deaths_bid_dod'],name='BID Cases',
                           line = dict(width=0.5, color='red')),row=2, col=1, secondary_y=True)
fig.add_trace(go.Scatter(x = df_mas_deaths['date'], y = df_mas_deaths['deaths_vax_total'],name='Deaths Vaccinated Cases',
                            line = dict(width=0.5, color='black')),row=2, col=1, secondary_y=True)
fig.add_trace(go.Scatter(x = df_mas_deaths['date'], y = df_mas_deaths['cum_deaths_vax'],name='Deaths Vaccinated Cases',
                            line = dict(width=1, color='black')),row=2, col=1, secondary_y=False)
#Graph 4
fig.add_trace(go.Scatter(x = df_mas_test['date'], y = df_mas_test['total_test'],name='Daily Covid19 Test',
                           line = dict(color='blue', width=0.5)),row=2, col=2, secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_test['date'], y = df_mas_test['cum_total'],name='Cumulative Covid19 Test',
                           line = dict(color='red', width=1)),row=2, col=2, secondary_y=True)
fig.add_hline(y=df_mas_test['total_test'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Daily Test", annotation_position="top left",row=2, col=2)
#Graph 5
fig.add_trace(go.Scatter(x = df_hosp_daily['date'], y = df_hosp_daily['admitted_covid'],name='Admitted',
                           line = dict(color='blue', width=0.5)),row=1, col=3, secondary_y=True)
fig.add_trace(go.Scatter(x = df_hosp_daily['date'], y = df_hosp_daily['discharged_covid'],name='Discharged',
                           line = dict(color='red', width=0.5)),row=1, col=3, secondary_y=True)
fig.add_trace(go.Scatter(x = df_hosp_daily['date'], y = df_hosp_daily['admitted_covid_cum'],name='Admitted',
                           line = dict(color='blue', width=1)),row=1, col=3, secondary_y=False)
fig.add_trace(go.Scatter(x = df_hosp_daily['date'], y = df_hosp_daily['discharged_covid_cum'],name='Discharged',
                           line = dict(color='red', width=1)),row=1, col=3, secondary_y=False)
fig.add_hline(y = df_hosp_daily['admitted_covid'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Admitted", annotation_position="bottom left",row=1, col=3)
fig.add_hline(y = df_hosp_daily['discharged_covid'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Discharged", annotation_position="top left",row=1, col=3)
#Graph 6
fig.add_trace(go.Scatter(x = df_pkrc_daily['date'], y = df_pkrc_daily['admitted_covid'],name='Admitted',
                           line = dict(color='blue', width=0.5)),row=1, col=4, secondary_y=True)
fig.add_trace(go.Scatter(x = df_pkrc_daily['date'], y = df_pkrc_daily['discharged_covid'],name='Discharged',
                           line = dict(color='red', width=0.5)),row=1, col=4, secondary_y=True)
fig.add_trace(go.Scatter(x = df_pkrc_daily['date'], y = df_pkrc_daily['admitted_covid_cum'],name='Admitted',
                           line = dict(color='blue', width=1)),row=1, col=4, secondary_y=False)
fig.add_trace(go.Scatter(x = df_pkrc_daily['date'], y = df_pkrc_daily['discharged_covid_cum'],name='Discharged',
                           line = dict(color='red', width=1)),row=1, col=4, secondary_y=False)
fig.add_hline(y = df_pkrc_daily['admitted_covid'].mean(), line_dash="dot",line_color="blue",
              annotation_text="Ave. Admitted", annotation_position="bottom left",row=1, col=4)
fig.add_hline(y = df_pkrc_daily['discharged_covid'].mean(), line_dash="dot",line_color="red",
              annotation_text="Ave. Discharged", annotation_position="top left",row=1, col=4)
#Graph 7
fig.add_trace(go.Bar(x = df_states_graph['state'], y = df_states_graph['admitted_covid'],name='Admitted Cases',
                       marker_color='blue'),row=2, col=3, secondary_y=False)
fig.add_trace(go.Bar(x = df_states_graph['state'], y = df_states_graph['discharged_covid'],name='Discharged Cases',
                       marker_color='red'),row=2, col=3, secondary_y=False)
#Graph 8
fig.add_trace(go.Bar(x = df_states_graph['state'], y = df_states_graph['vaksin_percentage_partial'],
                        name='Partial Vaksin (%)',marker_color='blue'),row=2, col=4, secondary_y=False)
fig.add_trace(go.Bar(x = df_states_graph['state'], y = df_states_graph['vaksin_percentage_full'],
                        name='Full Vaksin (%)',marker_color='red'),row=2, col=4, secondary_y=False)
#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=600,showlegend=False,title_text="Malaysia Covid19 Cases Overview", title_x=0.5)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

# add a horizontal line & annotations
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0=0, x1=16, xref="paper", y0=90, y1=90, yref="y",row=2, col=4)
fig.add_annotation(text='90% Vax. Pop.', x=6, y=90, arrowhead=1, showarrow=True,row=2, col=4)
#Plotting the graph
fig.show()
In [40]:
fig = make_subplots(rows=1, cols=4, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Total Daily Vax.</b>',
                '<b>Cumulative Daily Vax.</b>',
                '<b>Full, Partial & Booster</b>',
                '<b>Pfizer, Sinovac, AZ & Cansino</b>'))
#Graph 1
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['daily'],name='Total Daily Vaccinated',
                           line = dict(color='red',width=0.5)),row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['Vax. (%)'],name='Vax. (%)',
                           line = dict(color='blue',width=0.5)),row=1, col=1,secondary_y=True)
fig.add_hline(y=df_mas_vaksin['daily'].mean(), line_dash="dot",line_color="black",
              annotation_text="Ave. Daily Vax.", annotation_position="top left",row=1, col=1)
#Graph 2
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['Cum. Daily'],name='Cum. Daily Vaccinated',
                           line = dict(color='red',width=0.5)),row=1, col=2,secondary_y=False)
fig.add_hline(y=df_mas_vaksin['Cum. Daily'].mean(), line_dash="dot",line_color="black",
              annotation_text="Ave. Cum. Vax.", annotation_position="top left",row=1, col=2)
#Grpah 3
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['daily_partial'],name='Partial',
                           line = dict(color='red',width=0.5)),row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['daily_full'],name='Full',
                           line = dict(color='blue',width=0.5)),row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['daily_booster'],name='Booster',
                           line = dict(color='green',width=0.5)),row=1, col=3,secondary_y=True)
fig.add_hline(y=df_mas_vaksin['daily'].mean(), line_dash="dot",line_color="black",
              annotation_text="Ave. Daily Vax.", annotation_position="top left",row=1, col=3)
#Graph 4
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['Total Pfizer'],name='Pfizer',
                           line = dict(color='red',width=0.5)),row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['Total Sinovac'],name='Sinovac',
                           line = dict(color='blue',width=0.5)),row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['Total AstraZ'],name='Astra Zaneca',
                           line = dict(color='green',width=0.5)),row=1, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_mas_vaksin['date'], y = df_mas_vaksin['cansino'],name='Cansino',
                           line = dict(color='black',width=0.5)),row=1, col=4,secondary_y=True)
fig.add_hline(y=df_mas_vaksin['daily'].mean(), line_dash="dot",line_color="black",
              annotation_text="Ave. Daily Vax.", annotation_position="top left",row=1, col=4)
#Update Fonts & Size
fig.update_annotations(font=dict(family="Helvetica", size=11))
fig.update_layout(font=dict(family="Helvetica", size=11))
fig.update_layout(height=350,showlegend=False,title_text="Daily Vaccination Details", title_x=0.5)
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')

#Plotting the graph
fig.show()
In [41]:
#Forecasting of New Cases VS Recovered Cases
#Importing the required module
#from statsmodels.graphics.tsaplots import plot_acf, plot_pacf
#from statsmodels.tsa.statespace.varmax import VARMAX
#from statsmodels.tsa.api import VAR
#from statsmodels.tsa.stattools import grangercausalitytests, adfuller
#from tqdm import tqdm_notebook
#from itertools import product
#import statsmodels.api as sm
#import warnings
#warnings.filterwarnings('ignore')
#Importing the required datasets
#filepath_cases = 'https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/cases_malaysia.csv'
#filepath_deaths = "https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/deaths_malaysia.csv"
#filepath_vaksin = 'https://raw.githubusercontent.com/CITF-Malaysia/citf-public/main/vaccination/vax_malaysia.csv'
#Preparing the required datasets
#filepath_cases = pd.read_csv(filepath_cases, parse_dates=['date'], index_col='date').astype('float64')
#filepath_deaths = pd.read_csv(filepath_deaths, parse_dates=['date'], index_col='date').astype('float64')
#filepath_vaksin = pd.read_csv(filepath_vaksin, parse_dates=['date'], index_col='date').astype('float64')
#macro_data = pd.merge(filepath_cases,filepath_deaths,on='date')
#macro_data = pd.merge(macro_data,filepath_vaksin,on='date')
#macro_data['cases_vax_total'] = macro_data['cases_pvax'] + macro_data['cases_fvax']
#macro_data['deaths_vax_total'] = macro_data['deaths_pvax'] + macro_data['deaths_fvax']
#macro_data = macro_data[['cases_new','cases_active']]
#train_df=macro_data[:-12]
#test_df=macro_data[-360:]
#model = VAR(train_df.diff()[1:])
#sorted_order=model.select_order(maxlags=30)
#var_model = VARMAX(train_df, order=(4,0),enforce_stationarity= False)
#fitted_model = var_model.fit(disp=True)
#Creating the required forecast
#n_forecast = 180
#predict = fitted_model.get_prediction(start=len(train_df),end=len(train_df) + n_forecast-1)
#predictions=predict.predicted_mean
#predictions.columns=['cases_predicted','cases_active_predicted']
#test_vs_pred=pd.concat([test_df,predictions],axis=1)
#test_vs_pred = test_vs_pred.reset_index()
#test_vs_pred['cases_new_cum'] = test_vs_pred['cases_new'].cumsum()
#test_vs_pred['cases_active_cum'] = test_vs_pred['cases_active'].cumsum()
#test_vs_pred['cases_predicted_cum'] = test_vs_pred['cases_predicted'].cumsum()
#test_vs_pred['cases_active_predicted_cum'] = test_vs_pred['cases_active_predicted'].cumsum()
#Plotting the required forecast
#fig = make_subplots(specs=[[{'secondary_y': True}]])
#fig.add_trace(go.Scatter(x = test_vs_pred['index'], y = test_vs_pred['cases_new'], name ='Positive Cases', line = dict(color='blue', width=1)), secondary_y=True)
#fig.add_trace(go.Scatter(x = test_vs_pred['index'], y = test_vs_pred['cases_new_cum'], name ='Positive Cases', line = dict(color='blue', width=1)), secondary_y=False)
#fig.add_trace(go.Scatter(x = test_vs_pred['index'], y = test_vs_pred['cases_active'], name = 'Positive Cases After Vaccinated',line = dict(color='red', width=1)), secondary_y=True)
#fig.add_trace(go.Scatter(x = test_vs_pred['index'], y = test_vs_pred['cases_active_cum'], name = 'Positive Cases After Vaccinated',line = dict(color='red', width=1)), secondary_y=False)
#fig.add_trace(go.Scatter(x = test_vs_pred['index'], y = test_vs_pred['cases_predicted'], name = 'Predicted Positive Cases',line = dict(color='blue', width=0.75)), secondary_y=True)
#fig.add_trace(go.Scatter(x = test_vs_pred['index'], y = test_vs_pred['cases_active_predicted'], name = 'Predicted Positive Cases After Vaccinated',line = dict(color='red', width=0.75)), secondary_y=True)


#fig.update_layout(title_text='Malaysia Covid19 Forecast of Positive & Active Cases (Based on VAR Model)', title_x=0.5,showlegend=False, height=600)
#fig.update_xaxes(title_text='')
#fig.update_annotations(font=dict(family="Helvetica", size=12))
#fig.update_layout(font=dict(family="Helvetica", size=14))
#fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", x0='2021-10-11', x1='2021-10-11',  y0=0, y1=800000)
#fig.add_annotation(text='90% Adult Vax.', x='2021-10-11', y=800000, arrowhead=3, align='center', arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-90, showarrow=True, xanchor="left", yanchor="bottom")
#fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", x0='2021-11-20', x1='2021-11-20',  y0=0, y1=600000)
#fig.add_annotation(text='PRN Melaka', x='2021-11-20', y=600000, arrowhead=3, align='center', arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-90, showarrow=True, xanchor="left", yanchor="bottom")
#fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot", x0='2021-12-06', x1='2021-12-06',  y0=0, y1=500000)
#fig.add_annotation(text='PRN Sarawak', x='2021-12-06', y=500000, arrowhead=3, align='center', arrowsize=1, arrowwidth=2, arrowcolor="#636363",xref='x', ax=50, ay=-90, showarrow=True, xanchor="left", yanchor="bottom")
#fig.show()
In [42]:
df = df_states_cases
df_joh = df[df.state == 'Johor']
df_ked = df[df.state == 'Kedah']
df_kel = df[df.state == 'Kelantan']
df_mel = df[df.state == 'Melaka']
df_neg = df[df.state == 'Negeri Sembilan']
df_pah = df[df.state == 'Pahang']
df_prk = df[df.state == 'Perak']
df_per = df[df.state == 'Perlis']
df_pen = df[df.state == 'Pulau Pinang']
df_sab = df[df.state == 'Sabah']
df_sar = df[df.state == 'Sarawak']
df_sel = df[df.state == 'Selangor']
df_ter = df[df.state == 'Terengganu']
df_kul = df[df.state == 'W.P. Kuala Lumpur']
df_lab = df[df.state == 'W.P. Labuan']
df_put = df[df.state == 'W.P. Putrajaya']
fig = make_subplots(rows=4, cols=4, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Johor</b>', '<b>Kedah</b>', '<b>Kelantan</b>', '<b>Melaka</b>',
                '<b>Negeri Sembilan</b>', '<b>Pahang</b>', '<b>Perak</b>', '<b>Perlis</b>',
                '<b>Pulau Pinang</b>', '<b>Sabah</b>', '<b>Sarawak</b>', '<b>Selangor</b>',
                '<b>Terengganu</b>', '<b>W.P. Kuala Lumpur</b>', '<b>W.P. Labuan</b>', '<b>W.P. Putrajaya</b>'))
#Graph 1
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=1, col=1,secondary_y=False)
fig.add_hline(y=df_joh['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=1, col=1)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=1, col=1,secondary_y=True)
#Graph 2
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=1, col=2,secondary_y=False)
fig.add_hline(y=df_ked['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=1, col=2)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=1, col=2,secondary_y=True)
#Graph 3
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=1, col=3,secondary_y=False)
fig.add_hline(y=df_kel['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=1, col=3)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=1, col=3,secondary_y=True)
#Graph 4
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=1, col=4,secondary_y=False)
fig.add_hline(y=df_mel['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=1, col=4)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=1, col=4,secondary_y=True)
#Graph 5
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=2, col=1,secondary_y=False)
fig.add_hline(y=df_neg['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=2, col=1)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=2, col=1,secondary_y=True)
#Graph 6
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=2, col=2,secondary_y=False)
fig.add_hline(y=df_pah['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=2, col=2)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=2, col=2,secondary_y=True)
#Graph 7
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=2, col=3,secondary_y=False)
fig.add_hline(y=df_prk['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=2, col=3)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=2, col=3,secondary_y=True)
#Graph 8
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=2, col=4,secondary_y=False)
fig.add_hline(y=df_per['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=2, col=4)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=2, col=4,secondary_y=True)
#Graph 9
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=3, col=1,secondary_y=False)
fig.add_hline(y=df_pen['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=3, col=1)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=3, col=1,secondary_y=True)
#Graph 10
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=3, col=2,secondary_y=False)
fig.add_hline(y=df_sab['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=3, col=2)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=3, col=2,secondary_y=True)
#Graph 11
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=3, col=3,secondary_y=False)
fig.add_hline(y=df_sar['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=3, col=3)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=3, col=3,secondary_y=True)
#Graph 12
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=3, col=4,secondary_y=False)
fig.add_hline(y=df_sel['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=3, col=4)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=3, col=4,secondary_y=True)
#Graph 13
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=4, col=1,secondary_y=False)
fig.add_hline(y=df_ter['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=4, col=1)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=4, col=1,secondary_y=True)
#Graph 14
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=4, col=2,secondary_y=False)
fig.add_hline(y=df_kul['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=4, col=2)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=4, col=2,secondary_y=True)
#Graph 15
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=4, col=3,secondary_y=False)
fig.add_hline(y=df_lab['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=4, col=3)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=4, col=3,secondary_y=True)
#Graph 16
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['cases_new'],name='cases_new',
                        line = dict(color='red', width=0.75)), row=4, col=4,secondary_y=False)
fig.add_hline(y=df_put['cases_new'].mean(), line_dash="dot",line_color="red",
              annotation_text="Average Cases", annotation_position="top left",row=4, col=4)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['cases_recovered'],name='cases_recovered',
                        line = dict(color='blue', width=0.75)), row=4, col=4,secondary_y=True)
#Adding title and adjusting the layout
fig.update_layout(height=1000,showlegend=False,title_text="Covid19 Cases & Recovered At Each States",title_x=0.5)
fig.update_annotations(font=dict(family="Helvetica", size=10))
fig.update_layout(font=dict(family="Helvetica", size=12))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [43]:
df = df_states_deaths
df['deaths_vax_total'] = df['deaths_fvax'] + df['deaths_pvax'] 
df_joh = df[df.state == 'Johor']
df_ked = df[df.state == 'Kedah']
df_kel = df[df.state == 'Kelantan']
df_mel = df[df.state == 'Melaka']
df_neg = df[df.state == 'Negeri Sembilan']
df_pah = df[df.state == 'Pahang']
df_prk = df[df.state == 'Perak']
df_per = df[df.state == 'Perlis']
df_pen = df[df.state == 'Pulau Pinang']
df_sab = df[df.state == 'Sabah']
df_sar = df[df.state == 'Sarawak']
df_sel = df[df.state == 'Selangor']
df_ter = df[df.state == 'Terengganu']
df_kul = df[df.state == 'W.P. Kuala Lumpur']
df_lab = df[df.state == 'W.P. Labuan']
df_put = df[df.state == 'W.P. Putrajaya']
fig = make_subplots(rows=4, cols=4, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Johor</b>', '<b>Kedah</b>', '<b>Kelantan</b>', '<b>Melaka</b>',
                '<b>Negeri Sembilan</b>', '<b>Pahang</b>', '<b>Perak</b>', '<b>Perlis</b>',
                '<b>Pulau Pinang</b>', '<b>Sabah</b>', '<b>Sarawak</b>', '<b>Selangor</b>',
                '<b>Terengganu</b>', '<b>W.P. Kuala Lumpur</b>', '<b>W.P. Labuan</b>', '<b>W.P. Putrajaya</b>'))
#Graph 1
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=1,secondary_y=False)
fig.add_hline(y=df_joh['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=1, col=1)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=1,secondary_y=False)
#Graph 2
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=2,secondary_y=False)
fig.add_hline(y=df_ked['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=1, col=2)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=2,secondary_y=False)
#Graph 3
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=3,secondary_y=False)
fig.add_hline(y=df_kel['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=1, col=3)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=3,secondary_y=False)
#Graph 4
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=4,secondary_y=False)
fig.add_hline(y=df_mel['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=1, col=4)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=4,secondary_y=False)
#Graph 5
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=1,secondary_y=False)
fig.add_hline(y=df_neg['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=2, col=1)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=1,secondary_y=False)
#Graph 6
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=2,secondary_y=False)
fig.add_hline(y=df_pah['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=2, col=2)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=2,secondary_y=False)
#Graph 7
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=3,secondary_y=False)
fig.add_hline(y=df_prk['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=2, col=3)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=3,secondary_y=False)
#Graph 8
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=4,secondary_y=False)
fig.add_hline(y=df_per['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=2, col=4)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=4,secondary_y=False)
#Graph 9
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=3, col=1,secondary_y=False)
fig.add_hline(y=df_pen['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=3, col=1)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=1,secondary_y=False)
#Graph 10
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=3, col=2,secondary_y=False)
fig.add_hline(y=df_sab['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=3, col=2)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=2,secondary_y=False)
#Graph 11
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=3, col=3,secondary_y=False)
fig.add_hline(y=df_sar['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=3, col=3)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=3,secondary_y=False)
#Graph 12
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=3, col=4,secondary_y=False)
fig.add_hline(y=df_sel['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=3, col=4)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=4,secondary_y=False)
#Graph 13
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=4, col=1,secondary_y=False)
fig.add_hline(y=df_ter['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=4, col=1)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=1,secondary_y=False)
#Graph 14
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=4, col=2,secondary_y=False)
fig.add_hline(y=df_kul['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=4, col=2)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=2,secondary_y=False)
#Graph 15
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=4, col=3,secondary_y=False)
fig.add_hline(y=df_lab['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=4, col=3)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=3,secondary_y=False)
#Graph 16
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['deaths_new_dod'],name='Total Deaths',
                        line = dict(color='red', width=0.75)), row=4, col=4,secondary_y=False)
fig.add_hline(y=df_put['deaths_new_dod'].mean(), line_dash="dot",line_color="red", annotation_text="Average Deaths", 
              annotation_position="top left",row=4, col=4)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['deaths_vax_total'],name='Total Deaths Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=4,secondary_y=False)
#Adding title and adjusting the layout
fig.update_layout(height=1000,showlegend=False,title_text="Covid19 Daily Deaths Total & Vaccinated At Each States",title_x=0.5)
fig.update_annotations(font=dict(family="Helvetica", size=10))
fig.update_layout(font=dict(family="Helvetica", size=12))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [44]:
#Extracting And Separating Data For Each States
#Johor
df = df_states_vaksin
df_joh = df[df.state == 'Johor']
df_joh['cum_partial'] = df_joh['daily_partial'].cumsum()
df_joh['cum_full'] = df_joh['daily_full'].cumsum()
df_joh['cum_booster'] = df_joh['daily_booster'].cumsum()
#Kedah
df_ked = df[df.state == 'Kedah']
df_ked['cum_partial'] = df_ked['daily_partial'].cumsum()
df_ked['cum_full'] = df_ked['daily_full'].cumsum()
df_ked['cum_booster'] = df_ked['daily_booster'].cumsum()
#Kelantan
df_kel = df[df.state == 'Kelantan']
df_kel['cum_partial'] = df_kel['daily_partial'].cumsum()
df_kel['cum_full'] = df_kel['daily_full'].cumsum()
df_kel['cum_booster'] = df_kel['daily_booster'].cumsum()
#Melaka
df_mel = df[df.state == 'Melaka']
df_mel['cum_partial'] = df_mel['daily_partial'].cumsum()
df_mel['cum_full'] = df_mel['daily_full'].cumsum()
df_mel['cum_booster'] = df_mel['daily_booster'].cumsum()
#Negeri Sembilan
df_neg = df[df.state == 'Negeri Sembilan']
df_neg['cum_partial'] = df_neg['daily_partial'].cumsum()
df_neg['cum_full'] = df_neg['daily_full'].cumsum()
df_neg['cum_booster'] = df_neg['daily_booster'].cumsum()
#Pahang
df_pah = df[df.state == 'Pahang']
df_pah['cum_partial'] = df_pah['daily_partial'].cumsum()
df_pah['cum_full'] = df_pah['daily_full'].cumsum()
df_pah['cum_booster'] = df_pah['daily_booster'].cumsum()
#Perak
df_prk = df[df.state == 'Perak']
df_prk['cum_partial'] = df_prk['daily_partial'].cumsum()
df_prk['cum_full'] = df_prk['daily_full'].cumsum()
df_prk['cum_booster'] = df_prk['daily_booster'].cumsum()
#Perlis
df_per = df[df.state == 'Perlis']
df_per['cum_partial'] = df_per['daily_partial'].cumsum()
df_per['cum_full'] = df_per['daily_full'].cumsum()
df_per['cum_booster'] = df_per['daily_booster'].cumsum()
#Pulau Pinang
df_pen = df[df.state == 'Pulau Pinang']
df_pen['cum_partial'] = df_pen['daily_partial'].cumsum()
df_pen['cum_full'] = df_pen['daily_full'].cumsum()
df_pen['cum_booster'] = df_pen['daily_booster'].cumsum()
#Sabah
df_sab = df[df.state == 'Sabah']
df_sab['cum_partial'] = df_sab['daily_partial'].cumsum()
df_sab['cum_full'] = df_sab['daily_full'].cumsum()
df_sab['cum_booster'] = df_sab['daily_booster'].cumsum()
#Sarawak
df_sar = df[df.state == 'Sarawak']
df_sar['cum_partial'] = df_sar['daily_partial'].cumsum()
df_sar['cum_full'] = df_sar['daily_full'].cumsum()
df_sar['cum_booster'] = df_sar['daily_booster'].cumsum()
#Selangor
df_sel = df[df.state == 'Selangor']
df_sel['cum_partial'] = df_sel['daily_partial'].cumsum()
df_sel['cum_full'] = df_sel['daily_full'].cumsum()
df_sel['cum_booster'] = df_sel['daily_booster'].cumsum()
#Terengganu
df_ter = df[df.state == 'Terengganu']
df_ter['cum_partial'] = df_ter['daily_partial'].cumsum()
df_ter['cum_full'] = df_ter['daily_full'].cumsum()
df_ter['cum_booster'] = df_ter['daily_booster'].cumsum()
#Kuala Lumpur
df_kul = df[df.state == 'W.P. Kuala Lumpur']
df_kul['cum_partial'] = df_kul['daily_partial'].cumsum()
df_kul['cum_full'] = df_kul['daily_full'].cumsum()
df_kul['cum_booster'] = df_kul['daily_booster'].cumsum()
#Labuan
df_lab = df[df.state == 'W.P. Labuan']
df_lab['cum_partial'] = df_lab['daily_partial'].cumsum()
df_lab['cum_full'] = df_lab['daily_full'].cumsum()
df_lab['cum_booster'] = df_lab['daily_booster'].cumsum()
#Putrajaya
df_put = df[df.state == 'W.P. Putrajaya']
df_put['cum_partial'] = df_put['daily_partial'].cumsum()
df_put['cum_full'] = df_put['daily_full'].cumsum()
df_put['cum_booster'] = df_put['daily_booster'].cumsum()
In [45]:
fig = make_subplots(rows=4, cols=4, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Johor</b>', '<b>Kedah</b>', '<b>Kelantan</b>', '<b>Melaka</b>',
                '<b>Negeri Sembilan</b>', '<b>Pahang</b>', '<b>Perak</b>', '<b>Perlis</b>',
                '<b>Pulau Pinang</b>', '<b>Sabah</b>', '<b>Sarawak</b>', '<b>Selangor</b>',
                '<b>Terengganu</b>', '<b>W.P. Kuala Lumpur</b>', '<b>W.P. Labuan</b>', '<b>W.P. Putrajaya</b>'))
#Graph 1
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=1, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=1, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=1, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=1, col=1,secondary_y=False)
#Graph 2
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=1, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=1, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=1, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=1, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=1, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=1, col=2,secondary_y=False)
#Graph 3
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=1, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=1, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=1, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=1, col=3,secondary_y=False)
#Graph 4
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=1, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=1, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=1, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=1, col=4,secondary_y=False)
#Graph 5
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=2, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=2, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=2, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=2, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=2, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=2, col=1,secondary_y=False)
#Graph 6
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=2, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=2, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=2, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=2, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=2, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=2, col=2,secondary_y=False)
#Graph 7
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=2, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=2, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=2, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=2, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=2, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=2, col=3,secondary_y=False)
#Graph 8
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=2, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=2, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=2, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=2, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=2, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=2, col=4,secondary_y=False)
#Graph 9
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=3, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=3, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=3, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=3, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=3, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=3, col=1,secondary_y=False)
#Graph 10
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=3, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=3, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=3, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=3, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=3, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=3, col=2,secondary_y=False)
#Graph 11
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=3, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=3, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=3, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=3, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=3, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=3, col=3,secondary_y=False)
#Graph 12
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=3, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=3, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=3, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=3, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=3, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=3, col=4,secondary_y=False)
#Graph 13
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=4, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=4, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=4, col=1,secondary_y=True)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=4, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=4, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=4, col=1,secondary_y=False)
#Graph 14
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=4, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=4, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=4, col=2,secondary_y=True)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=4, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=4, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=4, col=2,secondary_y=False)
#Graph 15
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=4, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=4, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=4, col=3,secondary_y=True)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=4, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=4, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=4, col=3,secondary_y=False)
#Graph 16
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['daily_full'],name='Full',
                        line = dict(color='blue', width=0.75)), row=4, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['daily_partial'],name='Half',
                        line = dict(color='red', width=0.75)), row=4, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['daily_booster'],name='Booster',
                        line = dict(color='green', width=0.75)), row=4, col=4,secondary_y=True)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['cum_full'],name='Full',
                        line = dict(color='blue', width=1)), row=4, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['cum_partial'],name='Half',
                        line = dict(color='red', width=1)), row=4, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['cum_booster'],name='Booster',
                        line = dict(color='green', width=1)), row=4, col=4,secondary_y=False)
#Adding title and adjusting the layout
fig.update_layout(height=1000,showlegend=False,title_text="Covid19 Daily Vaccination (1D, 2D & 3D) At Each States",title_x=0.5)
fig.update_annotations(font=dict(family="Helvetica", size=10))
fig.update_layout(font=dict(family="Helvetica", size=12))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [46]:
dfpop = df_states_pop
#Creating new vax percentage columns at each states
#Johor
df_joh_pop = dfpop[dfpop.state == 'Johor']
df_joh_pop = df_joh_pop.at[df_joh_pop.index[0],'pop']
df_joh['2 Dos (%)'] = (df_joh['cum_full']/df_joh_pop)*100
#Kedah
df_ked_pop = dfpop[dfpop.state == 'Kedah']
df_ked_pop = df_ked_pop.at[df_ked_pop.index[0],'pop']
df_ked['2 Dos (%)'] = (df_ked['cum_full']/df_ked_pop)*100
#Kelantan
df_kel_pop = dfpop[dfpop.state == 'Kelantan']
df_kel_pop = df_kel_pop.at[df_kel_pop.index[0],'pop']
df_kel['2 Dos (%)'] = (df_kel['cum_full']/df_kel_pop)*100
#Melaka
df_mel_pop = dfpop[dfpop.state == 'Melaka']
df_mel_pop = df_mel_pop.at[df_mel_pop.index[0],'pop']
df_mel['2 Dos (%)'] = (df_mel['cum_full']/df_mel_pop)*100
#Negeri Sembilan
df_neg_pop = dfpop[dfpop.state == 'Negeri Sembilan']
df_neg_pop = df_neg_pop.at[df_neg_pop.index[0],'pop']
df_neg['2 Dos (%)'] = (df_neg['cum_full']/df_neg_pop)*100
#Pahang
df_pah_pop = dfpop[dfpop.state == 'Pahang']
df_pah_pop = df_pah_pop.at[df_pah_pop.index[0],'pop']
df_pah['2 Dos (%)'] = (df_pah['cum_full']/df_pah_pop)*100
#Perak
df_prk_pop = dfpop[dfpop.state == 'Perak']
df_prk_pop = df_prk_pop.at[df_prk_pop.index[0],'pop']
df_prk['2 Dos (%)'] = (df_prk['cum_full']/df_prk_pop)*100
#Perlis
df_per_pop = dfpop[dfpop.state == 'Perlis']
df_per_pop = df_per_pop.at[df_per_pop.index[0],'pop']
df_per['2 Dos (%)'] = (df_per['cum_full']/df_per_pop)*100
#Penang
df_pen_pop = dfpop[dfpop.state == 'Pulau Pinang']
df_pen_pop = df_pen_pop.at[df_pen_pop.index[0],'pop']
df_pen['2 Dos (%)'] = (df_pen['cum_full']/df_pen_pop)*100
#Sabah
df_sab_pop = dfpop[dfpop.state == 'Sabah']
df_sab_pop = df_sab_pop.at[df_sab_pop.index[0],'pop']
df_sab['2 Dos (%)'] = (df_sab['cum_full']/df_sab_pop)*100
#Sarawak
df_sar_pop = dfpop[dfpop.state == 'Sarawak']
df_sar_pop = df_sar_pop.at[df_sar_pop.index[0],'pop']
df_sar['2 Dos (%)'] = (df_sar['cum_full']/df_sar_pop)*100
#Selangor
df_sel_pop = dfpop[dfpop.state == 'Selangor']
df_sel_pop = df_sel_pop.at[df_sel_pop.index[0],'pop']
df_sel['2 Dos (%)'] = (df_sel['cum_full']/df_sel_pop)*100
#Terengganu
df_ter_pop = dfpop[dfpop.state == 'Terengganu']
df_ter_pop = df_ter_pop.at[df_ter_pop.index[0],'pop']
df_ter['2 Dos (%)'] = (df_ter['cum_full']/df_ter_pop)*100
#Kuala Lumpur
df_kul_pop = dfpop[dfpop.state == 'W.P. Kuala Lumpur']
df_kul_pop = df_kul_pop.at[df_kul_pop.index[0],'pop']
df_kul['2 Dos (%)'] = (df_kul['cum_full']/df_kul_pop)*100
#Labuan
df_lab_pop = dfpop[dfpop.state == 'W.P. Labuan']
df_lab_pop = df_lab_pop.at[df_lab_pop.index[0],'pop']
df_lab['2 Dos (%)'] = (df_lab['cum_full']/df_lab_pop)*100
#Putrajaya
df_put_pop = dfpop[dfpop.state == 'W.P. Putrajaya']
df_put_pop = df_put_pop.at[df_put_pop.index[0],'pop']
df_put['2 Dos (%)'] = (df_put['cum_full']/df_put_pop)*100
#Start creating the graph
fig = make_subplots(rows=4, cols=4, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Johor</b>', '<b>Kedah</b>', '<b>Kelantan</b>', '<b>Melaka</b>',
                '<b>Negeri Sembilan</b>', '<b>Pahang</b>', '<b>Perak</b>', '<b>Perlis</b>',
                '<b>Pulau Pinang</b>', '<b>Sabah</b>', '<b>Sarawak</b>', '<b>Selangor</b>',
                '<b>Terengganu</b>', '<b>W.P. Kuala Lumpur</b>', '<b>W.P. Labuan</b>', '<b>W.P. Putrajaya</b>'))
#Graph 1
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_joh['date'], y = df_joh['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=1,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=1, col=1)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=1, col=1)
#Graph 2
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=1, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ked['date'], y = df_ked['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=2,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=1, col=2)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=1, col=2)
#Graph 3
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_kel['date'], y = df_kel['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=3,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=1, col=3)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=1, col=3)
#Graph 4
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mel['date'], y = df_mel['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=1, col=4,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=1, col=4)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=1, col=4)
#Graph 5
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=2, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_neg['date'], y = df_neg['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=1,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=2, col=1)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=2, col=1)
#Graph 6
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=2, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_pah['date'], y = df_pah['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=2,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=2, col=2)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=2, col=2)
#Graph 7
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=2, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_prk['date'], y = df_prk['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=3,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=2, col=3)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=2, col=3)
#Graph 8
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=2, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_per['date'], y = df_per['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=2, col=4,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=2, col=4)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=2, col=4)
#Graph 9
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=3, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_pen['date'], y = df_pen['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=1,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=3, col=1)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=3, col=1)
#Graph 10
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=3, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sab['date'], y = df_sab['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=2,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=3, col=2)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=3, col=2)
#Graph 11
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=3, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sar['date'], y = df_sar['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=3,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=3, col=3)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=3, col=3)
#Graph 12
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=3, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sel['date'], y = df_sel['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=3, col=4,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=3, col=4)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=3, col=4)
#Graph 13
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=4, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ter['date'], y = df_ter['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=1,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=4, col=1)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=4, col=1)
#Graph 14
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=4, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_kul['date'], y = df_kul['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=2,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=4, col=2)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=4, col=2)
#Graph 15
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=4, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_lab['date'], y = df_lab['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=3,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=4, col=3)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=4, col=3)
#Graph 16
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['2 Dos (%)'],name='2 Dos (%)',
                        line = dict(color='red', width=0.75)), row=4, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_put['date'], y = df_put['daily'],name='Total Daily Vax',
                        line = dict(color='blue', width=0.75)), row=4, col=4,secondary_y=True)
fig.add_shape(type="line", line_color="salmon", line_width=3, opacity=1, line_dash="dot",
              x0='2021-3-1', x1=df_date_end.at[df_date_end.index[0],'date'], xref="x", y0=90, y1=90, 
              yref="y", row=4, col=4)
fig.add_annotation(text='90% Vax. Pop.', x='2021-3-1', y=90, arrowhead=1, arrowsize=1, arrowwidth=1,
                   ax=50, ay=-10, showarrow=True, xanchor="left", yanchor="bottom", row=4, col=4)
#Adding title and adjusting the layout
fig.update_layout(height=1000,showlegend=False,
                  title_text="Covid19 Vaccination Against Vaccination Per Population At Each States",title_x=0.5)
fig.update_annotations(font=dict(family="Helvetica", size=10))
fig.update_layout(font=dict(family="Helvetica", size=12))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [47]:
#Retrieving dataset for Covid19 for all countries
dfworld = pd.read_csv('https://raw.githubusercontent.com/datasets/covid-19/main/data/time-series-19-covid-combined.csv')
dfworld['daily_cases'] = dfworld['Confirmed'].diff()
dfworld['daily_recover'] = dfworld['Recovered'].diff()
dfworld['daily_deaths'] = dfworld['Deaths'].diff()
In [48]:
dfworld2 = pd.read_csv('https://raw.githubusercontent.com/owid/covid-19-data/master/public/data/latest/owid-covid-latest.csv')
dfworld2 = dfworld2[dfworld2['continent'].notna()] 
dfworld2 = dfworld2[['location','total_cases','total_deaths','people_vaccinated',
                     'population','population_density','gdp_per_capita']]
dfworld2['Cases (%)'] = (dfworld2['total_cases']/dfworld2['population'])*100
dfworld2['Deaths (%)'] = (dfworld2['total_deaths']/dfworld2['total_cases'])*100
dfworld2['Vaccination (%)'] = (dfworld2['people_vaccinated']/dfworld2['population'])*100

dfworld2.rename(columns={'location':'Country','total_cases':'Total Cases','total_deaths':'Total Deaths',
                         'people_vaccinated':'People Vaccinated','population':'Population',
                         'population_density':'Population Density','gdp_per_capita':'GDP Per Kapita'},inplace=True)
In [49]:
df_asean = dfworld2.loc[dfworld2['Country'].isin(['Malaysia','Singapore','Thailand','Indonesia',
                                              'Philippines','Cambodia','Laos','Vietnam',
                                              'Myanmar','Brunei'])]
df_asean = df_asean.sort_values('Total Cases',ascending=False)
def highlight_max(s):
    '''
    highlight the maximum in a Series Salmon.
    '''
    is_max = s == s.max()
    return ['background-color: salmon' if v else '' for v in is_max]

df_asean.style.set_caption("Overview Of Covid19 Cases In ASEAN Countries").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '26px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Total Cases':'{:,.0f}','Total Deaths':'{:,.0f}','People Vaccinated':'{:,.0f}','Population':'{:,.0f}',
     'Population Density':'{:,.1f}','GDP Per Kapita':'{:,.1f}','Cases (%)':'{:,.1f}','Deaths (%)':'{:,.1f}',
     'Vaccination (%)':'{:,.1f}'}).set_properties(subset=['Country'],**{'text-align': 'left'}).hide_index().apply(
    highlight_max,subset=['Total Cases','Total Deaths','People Vaccinated','Population','Population Density',
                          'GDP Per Kapita','Cases (%)','Deaths (%)','Vaccination (%)'])
Out[49]:
Overview Of Covid19 Cases In ASEAN Countries
Country Total Cases Total Deaths People Vaccinated Population Population Density GDP Per Kapita Cases (%) Deaths (%) Vaccination (%)
Vietnam 9,386,489 42,413 79,947,189 98,168,829 308.1 6,171.9 9.6 0.5 81.4
Indonesia 6,005,646 154,882 196,240,871 276,361,788 145.7 11,188.7 2.2 2.6 71.0
Malaysia 4,167,418 34,906 27,494,218 32,776,195 96.3 26,808.2 12.7 0.8 83.9
Philippines 3,677,616 59,038 70,173,137 111,046,910 351.9 7,599.2 3.3 1.6 63.2
Thailand 3,600,787 25,045 55,362,342 69,950,844 135.1 16,277.7 5.1 0.7 79.1
Singapore 1,085,094 1,258 5,005,722 5,453,600 7,915.7 85,535.4 19.9 0.1 91.8
Myanmar 611,275 19,430 26,473,700 54,806,014 81.7 5,591.6 1.1 3.2 48.3
Laos 171,439 663 5,593,478 7,379,358 29.7 6,397.4 2.3 0.4 75.8
Cambodia 135,552 3,054 14,814,942 16,946,446 90.7 3,645.1 0.8 2.3 87.4
Brunei 132,981 206 407,945 441,532 81.3 71,809.3 30.1 0.2 92.4
In [50]:
#Selecting datasets for ASEAN Countries
#Malaysia
dfworld.rename(columns={'Country/Region':'Country'},inplace=True)
df_mas = dfworld[dfworld.Country == 'Malaysia']
df_mas = df_mas.reset_index(drop=True)
df_mas = df_mas.drop([0])
#Indonesia
df_ind = dfworld[dfworld.Country == 'Indonesia']
df_ind = df_ind.reset_index(drop=True)
df_ind = df_ind.drop([0])
#Philippines
df_phi = dfworld[dfworld.Country == 'Philippines']
df_phi = df_phi.reset_index(drop=True)
df_phi = df_phi.drop([0])
#Burma
df_bur = dfworld[dfworld.Country == 'Burma']
df_bur = df_bur.reset_index(drop=True)
df_bur = df_bur.drop([0])
#Singapore
df_sin = dfworld[dfworld.Country == 'Singapore']
df_sin = df_sin.reset_index(drop=True)
df_sin = df_sin.drop([0])
#Thailand
df_tha = dfworld[dfworld.Country == 'Thailand']
df_tha = df_tha.reset_index(drop=True)
df_tha = df_tha.drop([0])
#Vietnam
df_vie = dfworld[dfworld.Country == 'Vietnam']
df_vie = df_vie.reset_index(drop=True)
df_vie = df_vie.drop([0])
#Cambodia
df_cam = dfworld[dfworld.Country == 'Cambodia']
df_cam = df_cam.reset_index(drop=True)
df_cam = df_cam.drop([0])
#Brunei
df_bru = dfworld[dfworld.Country == 'Brunei']
df_bru = df_bru.reset_index(drop=True)
df_bru = df_bru.drop([0])
#Laos
df_lao = dfworld[dfworld.Country == 'Laos']
df_lao = df_lao.reset_index(drop=True)
df_lao = df_lao.drop([0])
In [51]:
#Creating the ASEAN Covid19 Cases Graphs
fig = make_subplots(rows=2, cols=5, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Malaysia</b>', '<b>Indonesia</b>', '<b>Philippines</b>', '<b>Burma</b>', '<b>Singapore</b>',
                '<b>Thailand</b>', '<b>Vietnam</b>', '<b>Cambodia</b>', '<b>Brunei</b>', '<b>Laos</b>'))
#Row 1
#Graph 1
fig.add_trace(go.Scatter(x = df_mas['Date'], y = df_mas['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas['Date'], y = df_mas['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=1, col=1,secondary_y=True)
#Graph 2
fig.add_trace(go.Scatter(x = df_ind['Date'], y = df_ind['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=1, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ind['Date'], y = df_ind['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=1, col=2,secondary_y=True)
#Graph 3
fig.add_trace(go.Scatter(x = df_phi['Date'], y = df_phi['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_phi['Date'], y = df_phi['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=1, col=3,secondary_y=True)
#Graph 4
fig.add_trace(go.Scatter(x = df_bur['Date'], y = df_bur['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_bur['Date'], y = df_bur['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=1, col=4,secondary_y=True)
#Graph 5
fig.add_trace(go.Scatter(x = df_sin['Date'], y = df_sin['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=1, col=5,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sin['Date'], y = df_sin['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=1, col=5,secondary_y=True)
#Row 2
#Graph 6
fig.add_trace(go.Scatter(x = df_tha['Date'], y = df_tha['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=2, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_tha['Date'], y = df_tha['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=2, col=1,secondary_y=True)
#Graph 7
fig.add_trace(go.Scatter(x = df_vie['Date'], y = df_vie['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=2, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_vie['Date'], y = df_vie['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=2, col=2,secondary_y=True)
#Graph 8
fig.add_trace(go.Scatter(x = df_cam['Date'], y = df_cam['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=2, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_cam['Date'], y = df_cam['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=2, col=3,secondary_y=True)
#Graph 9
fig.add_trace(go.Scatter(x = df_bru['Date'], y = df_bru['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=2, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_bru['Date'], y = df_bru['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=2, col=4,secondary_y=True)
#Graph 10
fig.add_trace(go.Scatter(x = df_lao['Date'], y = df_lao['Confirmed'],name='Total Cases',
                        line = dict(color='red', width=2)), row=2, col=5,secondary_y=False)
fig.add_trace(go.Scatter(x = df_lao['Date'], y = df_lao['daily_cases'],name='Daily Cases',
                        line = dict(color='blue', width=0.75)), row=2, col=5,secondary_y=True)

#Adding title and adjusting the layout
fig.update_layout(height=500,showlegend=False,title_text="Covid19 Total And Daily Cases At ASEAN Countries",title_x=0.5)
fig.update_annotations(font=dict(family="Helvetica", size=10))
fig.update_layout(font=dict(family="Helvetica", size=12))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [52]:
#Creating the ASEAN Covid19 Cases Graphs
fig = make_subplots(rows=2, cols=5, specs=[[{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}],
                                           [{'secondary_y': True}, {'secondary_y': True},
                                            {'secondary_y': True}, {'secondary_y': True}, {'secondary_y': True}]],
                    
subplot_titles=('<b>Malaysia</b>', '<b>Indonesia</b>', '<b>Philippines</b>', '<b>Burma</b>', '<b>Singapore</b>',
                '<b>Thailand</b>', '<b>Vietnam</b>', '<b>Cambodia</b>', '<b>Brunei</b>', '<b>Laos</b>'))
#Row 1
#Graph 1
fig.add_trace(go.Scatter(x = df_mas['Date'], y = df_mas['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=1, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_mas['Date'], y = df_mas['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=1,secondary_y=True)
#Graph 2
fig.add_trace(go.Scatter(x = df_ind['Date'], y = df_ind['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=1, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_ind['Date'], y = df_ind['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=2,secondary_y=True)
#Graph 3
fig.add_trace(go.Scatter(x = df_phi['Date'], y = df_phi['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=1, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_phi['Date'], y = df_phi['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=3,secondary_y=True)
#Graph 4
fig.add_trace(go.Scatter(x = df_bur['Date'], y = df_bur['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=1, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_bur['Date'], y = df_bur['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=4,secondary_y=True)
#Graph 5
fig.add_trace(go.Scatter(x = df_sin['Date'], y = df_sin['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=1, col=5,secondary_y=False)
fig.add_trace(go.Scatter(x = df_sin['Date'], y = df_sin['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=1, col=5,secondary_y=True)
#Row 2
#Graph 6
fig.add_trace(go.Scatter(x = df_tha['Date'], y = df_tha['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=2, col=1,secondary_y=False)
fig.add_trace(go.Scatter(x = df_tha['Date'], y = df_tha['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=1,secondary_y=True)
#Graph 7
fig.add_trace(go.Scatter(x = df_vie['Date'], y = df_vie['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=2, col=2,secondary_y=False)
fig.add_trace(go.Scatter(x = df_vie['Date'], y = df_vie['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=2,secondary_y=True)
#Graph 8
fig.add_trace(go.Scatter(x = df_cam['Date'], y = df_cam['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=2, col=3,secondary_y=False)
fig.add_trace(go.Scatter(x = df_cam['Date'], y = df_cam['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=3,secondary_y=True)
#Graph 9
fig.add_trace(go.Scatter(x = df_bru['Date'], y = df_bru['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=2, col=4,secondary_y=False)
fig.add_trace(go.Scatter(x = df_bru['Date'], y = df_bru['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=4,secondary_y=True)
#Graph 10
fig.add_trace(go.Scatter(x = df_lao['Date'], y = df_lao['Deaths'],name='Total Deaths',
                        line = dict(color='blue', width=2)), row=2, col=5,secondary_y=False)
fig.add_trace(go.Scatter(x = df_lao['Date'], y = df_lao['daily_deaths'],name=' Daily Deaths',
                        line = dict(color='red', width=0.75)), row=2, col=5,secondary_y=True)

#Adding title and adjusting the layout
fig.update_layout(height=500,showlegend=False,title_text="Covid19 Total Deaths And Daily Cases At ASEAN Countries",title_x=0.5)
fig.update_annotations(font=dict(family="Helvetica", size=10))
fig.update_layout(font=dict(family="Helvetica", size=12))
fig.update_xaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showgrid=False, zeroline=False, showline=True, linewidth=2, linecolor='black')
#Plotting the graph
fig.show()
In [53]:
dfworld3 = dfworld2.sort_values('Total Cases',ascending=False).head(10)

def highlight_max(s):
    '''
    highlight the maximum in a Series Salmon.
    '''
    is_max = s == s.max()
    return ['background-color: salmon' if v else '' for v in is_max]

dfworld3.style.set_caption("Overview Of Top 10 Highest Covid19 Cases Worldwide").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '26px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Total Cases':'{:,.0f}','Total Deaths':'{:,.0f}','People Vaccinated':'{:,.0f}','Population':'{:,.0f}',
     'Population Density':'{:,.1f}','GDP Per Kapita':'{:,.1f}','Cases (%)':'{:,.1f}','Deaths (%)':'{:,.1f}',
     'Vaccination (%)':'{:,.1f}'}).set_properties(subset=['Country'],**{'text-align': 'left'}).hide_index().apply(
    highlight_max,subset=['Total Cases','Total Deaths','People Vaccinated','Population','Population Density',
                          'GDP Per Kapita','Cases (%)','Deaths (%)','Vaccination (%)'])
Out[53]:
Overview Of Top 10 Highest Covid19 Cases Worldwide
Country Total Cases Total Deaths People Vaccinated Population Population Density GDP Per Kapita Cases (%) Deaths (%) Vaccination (%)
United States 80,019,128 978,648 255,362,450 332,915,074 35.6 54,225.4 24.0 1.2 76.7
India 43,023,215 521,101 984,838,143 1,393,409,033 450.4 6,426.7 3.1 1.2 70.7
Brazil 29,887,191 659,508 181,078,067 213,993,441 25.0 14,103.5 14.0 2.2 84.6
France 25,329,455 142,054 53,993,210 67,422,000 122.6 38,605.7 37.6 0.6 80.1
United Kingdom 21,052,726 165,125 52,788,065 68,207,114 272.9 39,753.2 30.9 0.8 77.4
Germany 20,561,131 128,764 63,664,250 83,900,471 237.0 45,229.2 24.5 0.6 75.9
Russia 17,544,419 360,674 79,954,746 145,912,022 8.8 24,766.0 12.0 2.1 54.8
Turkey 14,831,231 97,924 57,776,278 85,042,736 104.9 25,129.3 17.4 0.7 67.9
Italy 14,496,579 159,054 50,723,408 60,367,471 205.9 35,220.1 24.0 1.1 84.0
South Korea 12,774,956 15,855 44,948,629 51,305,184 528.0 35,938.4 24.9 0.1 87.6
In [54]:
dfworld3 = dfworld2.sort_values('People Vaccinated',ascending=False).head(10)

def highlight_max(s):
    '''
    highlight the maximum in a Series Salmon.
    '''
    is_max = s == s.max()
    return ['background-color: salmon' if v else '' for v in is_max]

dfworld3.style.set_caption("Overview Of Top 10 Highest Covid19 People Vaccinated Worldwide").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '26px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Total Cases':'{:,.0f}','Total Deaths':'{:,.0f}','People Vaccinated':'{:,.0f}','Population':'{:,.0f}',
     'Population Density':'{:,.1f}','GDP Per Kapita':'{:,.1f}','Cases (%)':'{:,.1f}','Deaths (%)':'{:,.1f}',
     'Vaccination (%)':'{:,.1f}'}).set_properties(subset=['Country'],**{'text-align': 'left'}).hide_index().apply(
    highlight_max,subset=['Total Cases','Total Deaths','People Vaccinated','Population','Population Density',
                          'GDP Per Kapita','Cases (%)','Deaths (%)','Vaccination (%)'])
Out[54]:
Overview Of Top 10 Highest Covid19 People Vaccinated Worldwide
Country Total Cases Total Deaths People Vaccinated Population Population Density GDP Per Kapita Cases (%) Deaths (%) Vaccination (%)
China 217,576 4,638 1,275,541,000 1,444,216,102 147.7 15,308.7 0.0 2.1 88.3
India 43,023,215 521,101 984,838,143 1,393,409,033 450.4 6,426.7 3.1 1.2 70.7
United States 80,019,128 978,648 255,362,450 332,915,074 35.6 54,225.4 24.0 1.2 76.7
Indonesia 6,005,646 154,882 196,240,871 276,361,788 145.7 11,188.7 2.2 2.6 71.0
Brazil 29,887,191 659,508 181,078,067 213,993,441 25.0 14,103.5 14.0 2.2 84.6
Bangladesh 1,951,432 29,120 127,544,055 166,303,494 1,265.0 3,524.0 1.2 1.5 76.7
Japan 6,450,423 27,922 102,467,506 126,050,796 347.8 39,002.2 5.1 0.4 81.3
Mexico 5,654,311 322,845 85,580,293 130,262,220 66.4 17,336.5 4.3 5.7 65.7
Russia 17,544,419 360,674 79,954,746 145,912,022 8.8 24,766.0 12.0 2.1 54.8
Vietnam 9,386,489 42,413 79,947,189 98,168,829 308.1 6,171.9 9.6 0.5 81.4
In [55]:
dfworld3 = dfworld2.sort_values('Population',ascending=False).head(10)

def highlight_max(s):
    '''
    highlight the maximum in a Series Salmon.
    '''
    is_max = s == s.max()
    return ['background-color: salmon' if v else '' for v in is_max]

dfworld3.style.set_caption("Overview Of Top 10 Highest Population Countries Worldwide").set_table_styles([{
    'selector': 'caption',
    'props': [
        ('color', 'black'),
        ('font-size', '26px'),
        ("text-align", "center"),
        ('text-decoration', 'underline'),
        ('font-family','Arial'),
        ('text-shadow', '2px 2px 5px grey')
    ]},(dict
        (selector='th',props=[('text-align',
                               'left')]))]).format(
    {'Total Cases':'{:,.0f}','Total Deaths':'{:,.0f}','People Vaccinated':'{:,.0f}','Population':'{:,.0f}',
     'Population Density':'{:,.1f}','GDP Per Kapita':'{:,.1f}','Cases (%)':'{:,.1f}','Deaths (%)':'{:,.1f}',
     'Vaccination (%)':'{:,.1f}'}).set_properties(subset=['Country'],**{'text-align': 'left'}).hide_index().apply(
    highlight_max,subset=['Total Cases','Total Deaths','People Vaccinated','Population','Population Density',
                          'GDP Per Kapita','Cases (%)','Deaths (%)','Vaccination (%)'])
Out[55]:
Overview Of Top 10 Highest Population Countries Worldwide
Country Total Cases Total Deaths People Vaccinated Population Population Density GDP Per Kapita Cases (%) Deaths (%) Vaccination (%)
China 217,576 4,638 1,275,541,000 1,444,216,102 147.7 15,308.7 0.0 2.1 88.3
India 43,023,215 521,101 984,838,143 1,393,409,033 450.4 6,426.7 3.1 1.2 70.7
United States 80,019,128 978,648 255,362,450 332,915,074 35.6 54,225.4 24.0 1.2 76.7
Indonesia 6,005,646 154,882 196,240,871 276,361,788 145.7 11,188.7 2.2 2.6 71.0
Pakistan 1,524,549 30,349 nan 225,199,929 255.6 5,034.7 0.7 2.0 nan
Brazil 29,887,191 659,508 181,078,067 213,993,441 25.0 14,103.5 14.0 2.2 84.6
Nigeria 255,341 3,142 21,049,754 211,400,704 209.6 5,338.5 0.1 1.2 10.0
Bangladesh 1,951,432 29,120 127,544,055 166,303,494 1,265.0 3,524.0 1.2 1.5 76.7
Russia 17,544,419 360,674 79,954,746 145,912,022 8.8 24,766.0 12.0 2.1 54.8
Mexico 5,654,311 322,845 85,580,293 130,262,220 66.4 17,336.5 4.3 5.7 65.7

End Of Report